//ajax提交表单内容
function ajaxpost(form1){	
	ajaxpost_std(form1,1);
}

//ajax提交表单内容，无刷新
function ajaxnorefrespost(form1){	
	ajaxpost_std(form1,2);
}

/**
 * 统一处理表单内容
 * @param form1 表单id名称
 * @param way   表单处理成功动作
 */
function ajaxpost_std(form1,way){
	var obj=$("#"+form1);
	if(obj.data('lock'))return;							
	obj.data('lock', true);	
	$.post(obj.attr('action'),obj.serialize(),function(result){
		if(result.status==false){
			art.dialog({title:'消息',content:result.info,icon: 'error',fixed:true}).lock().time(2);
			obj.data('lock', false);  
			$("#verifyimg") && $("#verifyimg").click();
			return false;
		}
		if(1==way){
			art.dialog({title:'消息',content:result.info,icon:'succeed',fixed:true,close:function(){reload_std(result);}}).lock().time(2);
		}else if(2==way){
			art.dialog({title:'消息',content:result.info,icon:'succeed',fixed:true}).lock().time(2);
			obj.data('lock', false);			
		}
	})	
}

//提交链接，有提示
function ajaxget(url,cmsg){			
	artDialog(
	   {content:cmsg,lock:true,fixed:true,icon:'question',style:'confirm'}, 
	   function(){ajaxurl(url);}, //确认动作
	   function(){} //取消动作 
	);		
}

//提交链接，无提示
function ajaxurl(url){				
	$.getJSON(url,function(result){
		if(result.status==false){
			art.dialog({title:'消息',content:result.info,icon: 'error',fixed:true}).lock().time(2);			 
			return false;
		}
		art.dialog({title:'消息',content:result.info,icon: 'succeed',fixed:true,close:function(){reload_std(result);}}).lock().time(2);
	})
}

/**
 * 统一处理回调后页面动作
 * @param result 返回数据
 */
function reload_std(result){
	if(result.cmd==1){
		location.href=result.url;
	}else{
		location.reload(true);
	}	
}

//刷新二维码
function refreshimg(url,id){
	var obj=$("#"+id+"link");	
	if($(obj).data('lock'))return;							
	$(obj).data('lock', true).html('处理中...');	        
	$.getJSON(url,function(result){
        $("#"+id).attr("src",result.img);		
		$(obj).html('已生成');	        
	})
}

//ajax添加收藏
function ajaxsetcollect(id,type,len){
	var url=(1==type)?'/index/service/collect':'/index/service/addcart';
	var num= len || 1;
	$.getJSON(url,{gid:id,num:num},function(result){
		if(result.status==false){
			if('请登录'==result.info){ulogin();return;}
			art.dialog({title:'消息',content:result.info,icon: 'error',fixed:true}).lock().time(2);			 
			return false;
		}
		art.dialog({title:'消息',content:result.info,icon: 'succeed',fixed:true,close:function(){if(result.cmd==1){location.href=result.url;}else{location.reload();}}}).lock().time(2);
	})
}

//ajax添加购物车信息
function ajaxsetcart(id,len,gs){
	var url='/index/service/addcart';
	var num= len || 1;
	var gs=gs || '';
	$.getJSON(url,{gid:id,num:num,gs:gs},function(result){
		if(result.status==false){			
			art.dialog({title:'消息',content:result.info,icon: 'error',fixed:true}).lock().time(2);			 
			return false;
		}
		$("#cartgoodsnum").html(result.num); 		
	})
}

//用户登录窗口
function ulogin(){
	art.dialog.open("/public/ulogin",{title: '登录系统',id:'cats',width:350,height: 450,fixed:true,lock: true});	 
}

//用户退出登录
function ulogout(){			
	if(!confirm("确认退出登录？"))return false;
	$.getJSON("/user/logout.html",function(result){
		location.reload(true);
	})
}

//咨询窗口
function goodsmsg(id){
	art.dialog.open("/goods/goodsmsg?gid="+id,{title: '咨询预约',id:'cats',width:350,height:500,fixed:true,lock: true});	 
}